package com.example.texted.file;

import org.junit.Test;

import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class FileTest {
    public static void main(String[] args) {
        File file = new File("D:\\");
        List<String> fileNames = new ArrayList<>();
        findFileList(file,fileNames);
        fileNames.forEach(System.out::println);
    }

    public static void findFileList(File dir, List<String> fileNames) {
        if (!dir.exists() || !dir.isDirectory()) {// 判断是否存在目录
            System.out.println("目录不存在");
            return;
        }
        String[] files = dir.list();// 读取目录下的所有目录文件信息
        if (files == null) {
            System.out.println("无文件");
            return;
        }
        fileNames.addAll(Arrays.asList(files));
    }


    @Test
    public void san(){
        IntStream.rangeClosed(1,100).boxed().flatMap(a->
                IntStream.rangeClosed(a,100).mapToObj(b->
                        new  double[]{a,b,Math.sqrt(a*a+b*b)}
                        )
                ).filter(t->t[2]%1==0).forEach(f->System.out.println((int)f[0]+","+(int)f[1]+","+(int)f[2]));
    }
    @Test
    public void QQRen(){
        IntStream.rangeClosed(1,4).boxed().flatMap(a->
                IntStream.rangeClosed(1,4).boxed().flatMap(b->
                        IntStream.rangeClosed(1,4).mapToObj(c->new int[]{a,b,c})
                )
        ).forEach(f->System.out.println(f[0] +","+ f[1] +","+ f[2]));
    }
    @Test
    public void feibonaqoe(){
        Stream.iterate(new int[]{0, 1},
                t -> new int[]{t[1],t[0] + t[1]})
                .limit(20)
                .map(t -> t[0])
                .forEach(System.out::println);
    }
    @Test
    public void a(){
        Map<Boolean, List<Integer>> booleanListMap = partitionPrimes(10);
        booleanListMap.get(true).forEach(System.out::println);
    }
    public Map<Boolean, List<Integer>> partitionPrimes(int n) {
        return IntStream.rangeClosed(2, n).boxed()
                .collect(Collectors.partitioningBy(this::isPrime));
    }
    public boolean isPrime(int candidate) {
        int candidateRoot = (int) Math.sqrt(candidate);
        return IntStream.rangeClosed(2, candidateRoot)
                .noneMatch(i -> candidate % i == 0);
    }
}
